<template>
  <!-- eslint-disable vue/require-component-is -->
  <component v-bind="componentBind()" @closeComponent="closeComponent()" >
    <slot />
  </component>
</template>

<script>
import { closeTab } from '@/utils/index'
// const _import = require('@/router/_import_' + process.env.NODE_ENV)

const _import = function(file) {
  return require('@/views/' + file + '.vue').default
}
// 引入base64
const Base64 = require('js-base64').Base64

export default {
  data() {
    return {
      /**
       * 每个业务审核页面的组件路径
       * 键值规则为：
       *   1、审核页面：业务类型ID + 'Audit'
       *   2、提交（编辑）页面：业务类型ID + 'Edit'
       */
      auditDetailComponent: {
        wfBusiDemoAudit: 'workFlowManage/busiWorkFlowDemo/components/wfBusiDemoView',
        wfBusiDemoEdit: 'workFlowManage/busiWorkFlowDemo/components/wfBusiDemoDetail',
        // 业务Demo
        busiDemoInfoAudit: 'busiDemo/busiDemoInfo/busiDemoInfoView',
        busiDemoInfoEdit: 'busiDemo/busiDemoInfo/busiDemoInfoDetail',
        // 请假Demo
        busiLeaveInfoAudit: 'busiDemo/busiLeaveInfo/busiLeaveInfoView',
        busiLeaveInfoEdit: 'busiDemo/busiLeaveInfo/busiLeaveInfoDetail'
      }
    }
  },
  methods: {
    componentBind() {
      let routeQuery = this.$route.query
      // console.log('routeQuery', routeQuery)
      let queryArgs = routeQuery.queryArgs
      if (queryArgs) {
        let componentCustomProps = JSON.parse(Base64.decode(queryArgs))

        let taskType = componentCustomProps.taskType
        let handlingType = componentCustomProps.handlingType
        let openType = ''
        if (taskType === '01') {
          openType = 'audit'
          if (handlingType === '03') { // 驳回待办
            openType = 'edit'
          }
        } else if (taskType === '02') {
          openType = 'auditView'
        }

        // console.log('componentCustomProps', componentCustomProps)
        let componentPath = this.getComponentPath(componentCustomProps.busiTypeId, openType)

        if (componentPath) {
          componentCustomProps.openType = openType

          let componentDetail = _import(componentPath)

          return {
            is: componentDetail,
            componentCustomProps: componentCustomProps
          }
        }
      }
    },
    getComponentPath(busiTypeId, openType) { // 业务类型ID、表单查看类型
      let pathKey = busiTypeId + 'Audit'
      if (openType === 'edit') {
        pathKey = busiTypeId + 'Edit'
      }
      return this.auditDetailComponent[pathKey]
    },
    closeComponent() {
      //
      closeTab(this.$route)
    }
  }
}

</script>
<style scoped>

</style>
